<template>
	<view class="container">
		<view class="left-bottom-sign"></view>
		<view class="back-btn yticon icon-zuojiantou-up" @click="navBack"></view>
		<view class="right-top-sign"></view>
		<!-- 设置白色背景防止软键盘把下部绝对定位元素顶上来盖住输入框等 -->
		<view class="wrapper">
			<view class="left-top-sign">LOGIN</view>
			<view class="welcome">
				<image src="../../static/log.png"></image>
			</view>
			<view class="login-way">
				<text>尚街</text>
			</view>
			<view class="input-content">
				<!--账号密码登录-->
				<view class="input-item">
					<image  src="../../static/yonghu.png" class="tit"></image>
					<input type="text" v-model="username" placeholder="请输入用户名" maxlength="11" data-key="input" />
				</view>
				<view class="input-item">
					<image src="../../static/mima.png" class="tit"></image>
					<input type="text" v-model="password" placeholder="请输入密码" placeholder-class="input-empty" maxlength="20"
					 password data-key="password"  @confirm="toLogin" />
				</view>
				<view @click="navpwd" class="wpwd"><text>忘记密码?</text></view>

				<!--验证码登录-->
				<!-- <view class="input-item" v-if="loginWay == 1">
					<text class="tit">手机号</text>
					<input type="text" v-model="mobile" placeholder="请输入手机号码" maxlength="11" data-key="mobile" />
				</view>
				<view class="input-item" v-if="loginWay == 1">
					<view class="verify-code-selection">
						<text class="tit">验证码</text>
						<text class="btn-get-code" @click="getCode">获取验证码</text>
					</view>

					<input type="number" value="" placeholder="请输入验证码" placeholder-class="input-empty" maxlength="8" password data-key="code"
					 @input="inputChange" @confirm="toLogin" />
				</view> -->
			</view>
			<button class="confirm-btn" @click="toLogin" :disabled="logining">登录</button>
			<view class="register-section">
				还没有账号?
				<text @click="toRegist">立刻注册</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions
	} from 'vuex';

	export default {
		data() {
			return {
				username: '',
				password: '',
				logining: false,
				referer: null,
				mobile: '',
				code: ''
			}
		},
		onLoad(option) {
			this.referer = option.referer ? option.referer : null
		},
		methods: {
			...mapActions(['login', 'getCartProducts']),
			inputChange(e) {
				const key = e.currentTarget.dataset.key;
				this[key] = e.detail.value;
			},
			navpwd(){
				uni.navigateTo({
					url: "/pages/public/pwdorReg?types=2"
				})
			},
			navBack() {
				uni.navigateBack();
			},
			toRegist() {
				uni.navigateTo({
					url: "/pages/public/pwdorReg?types=1"
				})
			},
			toCenter() {
				uni.switchTab({
					url: '/pages/user/user'
				})
			},
			async toLogin() {
				this.logining = true;
				let sendData = {}
				const { username, password } = this;
				sendData = { username, password}
				this.login(sendData).then(res => {
					this.logining = false
					this.getCartProducts()
					if (this.referer) {
						uni.navigateTo({
							url: decodeURIComponent(this.referer),
							fail: this.toCenter(),
						})
					} else {
						this.toCenter()
					}
				}).catch(e => {
					this.logining = false
				})
			}
		},

	}
</script>

<style lang='scss'>
	page {
		background: url(../../static/beijing.png);
		background-size: 100% 100%;
	}

	.container {
		position: relative;
		width: 100vw;
		height: 100vh;
		overflow: hidden;
		background: url(../../static/beijing.png);
		background-size: 100% 100%;
	}

	.wrapper {
		position: relative;
		z-index: 90;
		padding-bottom: 40upx;
	}

	.back-btn {
		position: absolute;
		left: 40upx;
		z-index: 9999;
		padding-top: var(--status-bar-height);
		top: 40upx;
		font-size: 40upx;
		color: $font-color-dark;
	}

	.left-top-sign {
		font-size: 120upx;
		color: #FFFFFF;
		position: relative;
		left: -16upx;
	}

	.right-top-sign {
		position: absolute;
		top: 80upx;
		right: -30upx;
		z-index: 95;

		

		&:before {
			transform: rotate(50deg);
			border-radius: 0 50px 0 0;
		}

		&:after {
			position: absolute;
			right: -198upx;
			top: 0;
			transform: rotate(-50deg);
			border-radius: 50px 0 0 0;
			/* background: pink; */
		}
	}

	.left-bottom-sign {
		position: absolute;
		left: -270upx;
		bottom: -320upx;
		border-radius: 50%;
		padding: 180upx;
	}

	.welcome {
		font-size: 46upx;
		color: #555;
		text-align: center;
		image{
			width: 150upx;
			height: 150upx;
		}
	}

	.input-content {
		padding: 60upx 60upx 0 60upx;
	}

	.input-item {
		display: flex;
		justify-content: center;
		align-items: flex-start;
		flex-direction: row;
		padding: 0 30upx;
		height: 120upx;
		border-radius: 4px;
		margin-bottom: 50upx;

		&:last-child {
			margin-bottom: 0;
		}

		.tit {
			height: 50upx;
			width: 50upx;
		}
		input{
				margin-left: 19upx;
				line-height: 1.6em;
				height: 1.6em;
				width: 110%;
				border-bottom: 1px solid #C0C4CC;
		}		
		&input {
			height: 70upx;
			font-size: $font-base;
			background: $page-color-light;
			color: $font-color-dark;
			width: 100%;
		}
	}
	.wpwd{
		position: absolute;
		right: 90upx;
		font-size: $font-sm+2upx;
		color: $font-color-base;
	}
	.confirm-btn {
		margin: 0 auto;
		width: 75%;
		height: 76upx;
		line-height: 76upx;
		border-radius: 25px;
		margin-top: 130upx;
		background: #FE6464;
		color: #fff;
		font-size: $font-lg;

		&:after {
			border-radius: 100px;
		}
	}

	.forget-section {
		font-size: $font-sm+2upx;
		color: $font-color-spec;
		text-align: center;
		margin-top: 40upx;
	}

	.register-section {
		position: absolute;
		left: 0;
		bottom: -20px;
		width: 100%;
		font-size: $font-sm+2upx;
		color: $font-color-base;
		text-align: center;
		letter-spacing:5upx;
		text {
			color: #FE6464;
			margin-left: 10upx;
		}
	}

	.login-way {
		display: flex;
		flex-direction: row;
		font-size: 23px;
		justify-content: center;
		font-weight: bold;
		color: #FE6464;
	}
</style>
